package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.RoleService;

import com.itheima.entity.PageResult1;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Role;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Reference
    private RoleService roleService;
    @RequestMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult1 pageResult =  roleService.findPage(queryPageBean);
        return Result.success("",pageResult);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Role role) {
        try {
            roleService.add(role);
            return Result.success("添加成功");

        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("添加失败");
        }
    }

    @RequestMapping("/delete")
    public Result delete(@RequestParam("id") Integer id) {
        try {
            roleService.delete(id);

            return Result.success("删除成功");
        } catch (Exception e) {

            e.printStackTrace();
            return Result.error("删除失败,联系管理员");
        }
    }



}
